<?php
require_once 'config.php';
require_once '../conf/conf.php';
require_once 'class/Mysql.class.php';
require_once '../includes/lib_common.php';

if (!defined('IN_WONDERSHARE')) die('Hacking attempt');

$db = new Mysql();
if($_GET['search']) {$search = " and `message` like '%{$_GET['search']}%'";}
if($_GET['person']) {$search .= " and `author` = '{$_GET['person']}'";}
$sid = $_GET['sid'];
$limit = 20;
$page = max( 1, $_GET['page'] );
$offest = ($page-1)*$limit;

$site = $site_disqus[$sid];

$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM ".DB_TABLE_PRE."comment WHERE site = '{$site}' {$search} ORDER BY is_create ASC, cid DESC LIMIT {$offest}, {$limit}";
$data = $db->getAll( $sql );
$num = $db->getNum();

foreach( $data as $k=>$v ){
	$url = $v['url'];
	if( $v['site'] == 'ws-jp' ){
		$url = str_replace('wondershare.jp/', 'wondershare.jp/httpdocs/', $url);
	}elseif( $v['site'] == 'ws-de' ){
		$url = str_replace('wondershare.de/', 'wondershare.de/httpdocs/', $url);
	}else{
		$url = str_replace($v['site'].'.com/', $v['site'].'.com/httpdocs/', $url);
	}
	
	$url = str_replace('http://www.', 'http://check.wondershare.com/', $url);
	$data[$k]['url'] = $url;
}

$pages = get_page_url( $page, ceil($num / $limit), '&search='.$_GET['search'].'&person='.$_GET['person'] );

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="../wondershare/styles/main.css" rel="stylesheet" type="text/css" />
<link href="../wondershare/styles/general.css" rel="stylesheet" type="text/css" />
<!--此处要用jquery 1.6 否则$("#myform").attr('action','xxx')无效-->
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript">
//note 全选
function selectAll( obj ){
	if( $(obj).attr('checked') ){
		$("tr[id^='tr_'] input[type='checkbox']").each(function(){
			$(this).attr('checked',true);	
		})
	}else{
		$("tr[id^='tr_'] input[type='checkbox']").each(function(){
			$(this).attr('checked',false);	
		})
	}
}

function create( obj ){
	$(obj).val('正在生成...');
	$(obj).attr('disabled','disabled');
	
	$("tr[id^='tr_'] input[type='checkbox']").each(function(){
		var did = parseInt($(this).attr('did'));
		if( did == 0 ){
			$(this).remove();
			return;
		}
		$(this).attr('name','ID['+did+']');
		$(this).val($(this).attr('did'));
	})
	
	$("#myform").attr('action','../bin/docList_<?php echo $site_config[$site]['table'];?>.php?is_disqus_pub=1&sid=<?php echo $sid;?>');
	$("#myform").submit();
}

function del(){
	$("tr[id^='tr_'] input[type='checkbox']").each(function(){
		$(this).attr('name','cid[]');
		$(this).val($(this).attr('cid'));
	})
	
	$("#myform").attr('action','./syn_comment.php?m=del&sid=<?php echo $sid;?>');
	$("#myform").submit();
}

function searchFun(){
	document.location.href = document.location.href+ "&search="+encodeURI( $('#search').val())+"&person="+encodeURI( $('#person').val());
}
</script>
</head>

<body style="padding-top:5px;">
【<?php echo $site;?>】站点的文章评论列表，该列表只显示Disqus后台Approved状态下的评论
<form method="post" id="myform">
<table cellpadding="2" cellspacing="1" width="100%" class="list-div">
<tr>
  <td colspan="7"> 搜索内容: <input type="text" value="<?php echo $_GET['search']?>" name="search" size="20" id="search" /> 
  评论人:<input type="text" value="<?php echo $_GET['person']?>" name="person" size="10" id="person" /> 
  <input type="button" value="提交" onclick="searchFun()" /></td>
</tr>
<tr><th width="60">文章ID</th><th width="30">操作</th><th>文章地址</th><th width="80">评论人</th><th>内容</th><th>时间</th><th width="50">状态</th></tr>
<?php foreach( $data as $k=>$v ){?>
<tr id="tr_<?php echo $k;?>">
  <td><label><input type="checkbox" cid="<?php echo $v['cid'];?>" did="<?php echo $v['d_id'];?>" /><?php echo $v['article_id'];?></label></td>
  <td align="center"><?php if($v['d_id']>0){?><a href="../bin/preview.php?do=view&TID=<?php echo $site_config[$site_disqus[$sid]]['table'];?>&D_ID=<?php echo $v['d_id'];?>" target="_blank">预览</a><?php }?></td>
  <td><a href="<?php echo $v['url'];?>" target="_blank"><?php echo $v['url'];?></a></td>
  <td align="center"><?php echo $v['author'];?></td>
  <td><?php echo $v['message'];?></td>
  <td><?php echo $v['time'];?></td>
  <td align="center"><?php echo $v['is_create'] == 1 ? '<span style="color:green">已生成</span>' : '<span style="color:red">'.($v['d_id']>0?'未生成':'无法生成').'</span>';?></td>
</tr>
<?php }?>
<tr>
  <td colspan="7">
  <label><input type="checkbox" onclick="selectAll( this )" /> 全选</label>&nbsp;&nbsp;&nbsp;
  <input type="button" value="生成选中项" onclick="create(this)" />&nbsp;
  <input type="button" value="删除选中项" onclick="del()" />&nbsp;&nbsp;&nbsp;
  <input type="hidden" value="true" name="doPost" />
  <input type="hidden" value="<?php echo $site_config[$site]['table']; ?>" name="TID" />
  <input type="hidden" value="pub" name="action" />
  <?php echo $pages;?></td></tr>
</table>
</form>
</body>
</html>
